<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登陆</title>
    <link rel="stylesheet" href="__STATIC__/jquery-weui/dist/lib/weui.css">
    <link rel="stylesheet" href="__STATIC__/jquery-weui/dist/css/jquery-weui.css">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

    <meta name="description" content="Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.">
</head>
<body>
<div class="weui-cells weui-cells-form">
    <div class="weui-cell weui-cell_vcode">
        <div class="weui-cell__hd">
            <label class="weui-label">手机号</label>
        </div>
        <div class="weui-cell__bd">
            <input id="mobile" name="mobile" class="weui-input" type="tel" placeholder="请输入手机号">
        </div>
        <div class="weui-cell__ft">
            <button class="weui-vcode-btn" id="getCode">获取验证码</button>
        </div>
    </div>
    <div class="weui-cell weui-cell_vcode">
        <div class="weui-cell__hd"><label class="weui-label">验证码</label></div>
        <div class="weui-cell__bd">
            <input id="code" class="weui-input" name="code" type="number" placeholder="请输入验证码">
        </div>
    </div>
    <div class="weui-btn-area">
        <a class="weui-btn weui-btn_primary" id="login">
            登陆
        </a>
    </div>
    <div class="weui-cells__tips">资金有限,每月100条短信,用完就没了~__~</div>
</div>
<script src="__STATIC__/jquery-weui/dist/lib/jquery-2.1.4.js"></script>
<script src="__STATIC__/jquery-weui/dist/js/jquery-weui.js"></script>
<script src="/copy_QQ/public/js/index/getName.js"></script>
<script>
    $(function () {
        //获取验证码
        $("#getCode").on("click",function (e) {
            var mobile=$("#mobile").val();
            $.ajax({
                url:'{:url("getCode")}',
                type:"post",
                dataType:"json",
                data:{
                    mobile:mobile,
                },
                success:function (res) {
                    console.log(res);
                    if(res.result!=-1){
                        if(res.result==0){
                            $.toptip("验证码发送成功",2000,"success");
                        }else{
                            $.toptip("验证码发送失败",2000,"error");
                            $.alert({
                                title: res.errmsg,
                                text: '验证码:'+res.code,
                                onOK: function () {
                                    //点击确认
                                    $("#code").val(res.code);
                                }
                            });
                        }
                    }else{
                        $.alert({
                            title: res.errmsg,
                            text:"请重新发送",
                            onOK: function () {
                                //点击确认
                            }
                        });
                    }

                },
                fail:function (res) {
                    //console.log("网络错误!");
                    $.alert({
                        title:"提示",
                        text:"网络错误"
                    });
                }
            });
        });

        //登陆事件
        $("#login").on("click",function (e) {
            var mobile=$("#mobile").val(),code=$("#code").val();
            $.ajax({
                url:"{:url('login')}",
                type:"POST",
                data:{
                    mobile:mobile,
                    code:code
                },
                dataType:"json",
                success:function (res) {
                    //console.log(res);
                    if(res.result==0){
                        var timeid=-1;
                        $.prompt({
                            title:"输入昵称",
                            text:"昵称不能为空(千万不要点取消)",
                            input: getName(),
                            empty: false, // 是否允许为空
                            onOK: function (input) {
                                //点击确认
                                if(timeid!=-1){
                                    clearInterval(timeid);
                                }
                                sessionStorage.setItem("nickname",input);
                                $.toast("登陆成功");
                                location.href="{:url('index/index/index')}"
                            },
                            onCancel: function () {
                                //点击取消
                                $.toast("登陆失败");
                                timeid=setInterval(function () {
                                    $.alert("每5s弹出一次,请尽快登陆","轰炸机~_~");
                                },5000);
                            }
                        });

                    }else {
                        $.alert("验证码错误","提示");
                    }
                },
                fail:function (res) {
                    //console.log("网络错误!");
                    $.alert({
                        title:"提示",
                        text:"网络错误"
                    });
                }
            });
        });
    });
</script>
</body>
</html>